exports.setImageWatermark = function(req,res){


    var path = require("path");
    var fs   = require("fs");

    //获取body参数
    var bodyParams = req.routeInfo.bodyParams;

    //根据位置获取最终值
    var position = "SouthEast";
    if(bodyParams.position != undefined){
        if(bodyParams.position == 'leftTop'){
            position = "NorthWest";
        }else if(bodyParams.position == 'leftBottom'){
            position = "SouthWest";
        }else if(bodyParams.position == 'rightTop'){
            position = "NorthEast";
        }else if(bodyParams.position == 'rightBottom'){
            position = "SouthEast";
        }else if(bodyParams.position == 'center'){
            position = "Center";
        }
    }
    

    //判断是否有水印图参数
    // var waterMark = "./" + config.fileManager.baseDir + "/" + config.fileManager.configFile + "/" +  config.uploadImageConfig.watermarkDefaultImage;
    // if(bodyParams.waterMarkUrl == undefined){
    //    waterMark = bodyParams.waterMarkUrl;
    // }

    //获取要处理的文件名称
    var imageUrl = path.basename(bodyParams.srcImageUrl);

    //处理完成后的图片名称
    var newFileName = "w_" + imageUrl;
    // console.log(waterMark)
    // console.log(1111111)
    // console.log(bodyParams.waterMarkUrl == undefined)


        // fs.exists(waterMark, function(exists) {




            // if(!exists){
            //     return RES.errorResponse(res,"本地的默认水印文件不存在，请先设置在进行使用，或传递网络水印图片路径");
            // }
            // console.log(3333)

            //打水印-图片
            GM(bodyParams.srcImageUrl)
            .composite(bodyParams.waterMarkUrl)
            .gravity(position)
            .geometry('+5+5')
            .write("./" + config.fileManager.baseDir + "/" + config.uploadImageConfig.imageParocessingDir + "/" + newFileName, function (err) {
                console.log(4444)
                console.log(err)
                if(err){
                    console.log(err);
                    return RES.errorResponse(res,"文件水印设置失败");
                }
                console.log(5555)
                console.log(config.server.ip + ":" + config.server.port + "/" + config.uploadImageConfig.imageParocessingDir + "/" + newFileName)

                RES.successResponse(res,config.server.ip + ":" + config.server.port + "/" + config.uploadImageConfig.imageParocessingDir + "/" + newFileName);
            })

    
        // });


    
    //生成缩略图
    /*
    var gm = require('gm').subClass({imageMagick: true})
    gm("./file/images/" + "dongtai_bg_2.jpg")
    .resize(200).write("./file/images/th_dongtai_bg_2.jpg", function (err) {
        if (err) console.log(err);
        console.log("完成");
    })
    */

   //打水印-文字版
   //SouthWest 左下角
   //SouthEast 右下角
   //NorthEast 右上角
   //NorthWest 左上角
//    var gm = require('gm').subClass({imageMagick: true})
//    gm("./file/images/" + "dongtai_bg_2.jpg")
//    .fill('#ffffff')
//    .font('./fonts/fangzhengkaiti.ttf')
//    .fontSize(20)
//    .drawText(5,5,"呵呵哒",'SouthEast').write("./file/images/watermark_dongtai_bg_2.jpg", function (err) {
//        if(err){
//             console.log(err);
//        }
//        console.log("完成");
//    })

    

    //裁剪-图片
    // var gm = require('gm').subClass({imageMagick: true})
    // gm("./file/images/" + "dongtai_bg_2.jpg")
    // .crop(50,50,10,10)
    // .write("./file/images/crop_dongtai_bg_2.jpg", function (err) {
    //     if(err){
    //             console.log(err);
    //     }
    //     console.log("完成");
    // })

    // //压缩-图片
    // var gm = require('gm').subClass({imageMagick: true})
    // // gm("./file/images/" + "dongtai_bg_2.jpg")
    // gm("https://e-d.oss-cn-beijing.aliyuncs.com/system_header/system_header_03.png")
    // // .resize(50)
    // .write("./file/images/network.jpg", function (err) {
    //     if(err){
    //             console.log(err);
    //     }
    //     console.log("完成");
    // })

}